package c.c.b.a.b;

import c.c.b.a.b.a.e;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Objects;

/* compiled from: Headers */
public final class v {
    public final String[] a;

    /* compiled from: Headers */
    public static final class a {
        public final List<String> a = new ArrayList(20);

        public a a(String str) {
            int i = 0;
            while (i < this.a.size()) {
                if (str.equalsIgnoreCase((String) this.a.get(i))) {
                    this.a.remove(i);
                    this.a.remove(i);
                    i -= 2;
                }
                i += 2;
            }
            return this;
        }

        public a b(String str, String str2) {
            this.a.add(str);
            this.a.add(str2.trim());
            return this;
        }

        public final void c(String str, String str2) {
            Objects.requireNonNull(str, "name == null");
            if (str.isEmpty()) {
                throw new IllegalArgumentException("name is empty");
            }
            int i;
            char charAt;
            int length = str.length();
            for (i = 0; i < length; i++) {
                charAt = str.charAt(i);
                if (charAt <= ' ' || charAt >= 127) {
                    throw new IllegalArgumentException(e.i("Unexpected char %#04x at %d in header name: %s", Integer.valueOf(charAt), Integer.valueOf(i), str));
                }
            }
            if (str2 != null) {
                length = str2.length();
                i = 0;
                while (i < length) {
                    charAt = str2.charAt(i);
                    if ((charAt > 31 || charAt == 9) && charAt < 127) {
                        i++;
                    } else {
                        throw new IllegalArgumentException(e.i("Unexpected char %#04x at %d in %s value: %s", Integer.valueOf(charAt), Integer.valueOf(i), str, str2));
                    }
                }
                return;
            }
            throw new NullPointerException(c.b.a.a.a.E("value for name ", str, " == null"));
        }
    }

    public v(a aVar) {
        List list = aVar.a;
        this.a = (String[]) list.toArray(new String[list.size()]);
    }

    public int a() {
        return this.a.length / 2;
    }

    public String b(int i) {
        return this.a[i * 2];
    }

    public String c(String str) {
        String[] strArr = this.a;
        int length = strArr.length;
        do {
            length -= 2;
            if (length < 0) {
                return null;
            }
        } while (!str.equalsIgnoreCase(strArr[length]));
        return strArr[length + 1];
    }

    public String d(int i) {
        return this.a[(i * 2) + 1];
    }

    public a e() {
        a aVar = new a();
        Collections.addAll(aVar.a, this.a);
        return aVar;
    }

    public boolean equals(Object obj) {
        return (obj instanceof v) && Arrays.equals(((v) obj).a, this.a);
    }

    public int hashCode() {
        return Arrays.hashCode(this.a);
    }

    public String toString() {
        StringBuilder stringBuilder = new StringBuilder();
        int a = a();
        for (int i = 0; i < a; i++) {
            stringBuilder.append(b(i));
            stringBuilder.append(": ");
            stringBuilder.append(d(i));
            stringBuilder.append("\n");
        }
        return stringBuilder.toString();
    }
}
